from typing import Union


def m2c(marks: list[dict[str, Union[str, float]]]) -> list[dict[str, float]]:
    '''Transforms marks to clips to be preserved.

    ## Parameters

    marks: list[dict]
        A list of dict, each element of which contains only 3 keys, namely
        `label`, `start` and `end`, representing the type of the mark,
        start second, end second respectively.\\
        Example:

            [
                {
                    "label": "bad",
                    "start": 1.14,
                    "end": 5.14
                },
                {
                    "label": "good",
                    "start": 6,
                    "end": 10.01
                },
                {
                    "lable": "good",
                    "start": 19.19,
                    "end": 20
                }
            ]

    ## Returns

    ret: list[dict[str, float]]
        A list of dict, each of element of which contains only 2 keys, namely
        `start` and `end`, representing the start second and end second of
        the preserved clip respectively.\\
        Example:

        [
            {
                "start": 5.14,
                "end": 6
            },
            {
                "start": 10.01,
                "end": 19.19
            },
            {
                "start": 20,
                "end": 2147483647
            }
        ]
    '''
    marks.sort(key=lambda x: x['start'])
    ret: list[dict[str, float]] = []
    start: float = 0
    for mark in marks:
        if mark['label'] == 'good':
            ret.append({'start': float(start), 'end': float(mark['start'])})
        start = float(mark['end'])
    #print("util",ret)
    #ret.append({'start': start, 'end': 2147483647}) #保留最后一个标记到结尾的部分
    return ret
